<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/12
 * Time: 9:58
 */

function setWhereStr ($arr):string {
    $str = '\'';
    foreach ($arr as $key=>$val){
        $str .=$val.'\',\'';
    }

    return substr($str,0,-2);
}
$timeStart = microtime(true);
require_once ("./SqlService.php");
require_once ("./StudentService.php");

$sqlService = new SqlService();

/**
 * 第一步对学校学生的
 */

/**
 * 天台岗总校id
 */
$chief = 1;


/**
 * 天台岗学校
 */
$schoolSqlRes =  $sqlService->db->query("select * from aigoo_school   where chief=$chief");
$schoolList = $schoolSqlRes->fetch_all();
$schoolIds = array();

foreach ($schoolList as $key=>$val){
    $schoolIds[] = $val[0];
}

$schoolWhereInStr = setWhereStr($schoolIds);
/**
 * 当前的学校的年级
 *
 */

$nowSchoolGrade =StudentService::getInGrade();
//array(6) { [0]=> int(2018) [1]=> int(2019) [2]=> int(2020) [3]=> int(2021) [4]=> int(2022) [5]=> int(2023) }
$nowSchoolGradeKey = array_keys($nowSchoolGrade);
$gradeWhereInStr = setWhereStr($nowSchoolGradeKey);
//array(6) { [0]=> string(9) "六年级" [1]=> string(9) "五年级" [2]=> string(9) "四年级" [3]=> string(9) "三年级" [4]=> string(9) "二年级" [5]=> string(9) "一年级" }
$nowSchoolGradeVal = array_values($nowSchoolGrade);


/**
 * 获取班级列表
 */

$gradeSqlRes = $sqlService->db->query("select * from aigoo_schoolclass   where chiefid=$chief and schoolid in ($schoolWhereInStr) and gradeyear in ($gradeWhereInStr)");

var_dump($gradeSqlRes);



//echo  json_encode($schoolSqlRes->fetch_all());die();


/*$baby =  $sqlService->db->query("select * from aigoo_baby limit 3");

foreach ($baby as $key=>$val){
    var_dump($val);
}*/



$sqlService->close();

$timeEnd = microtime(true);
//echo $timeEnd-$timeStart;